from typing import Dict, Any, Optional, List
from constants.recognition import RecognitionStrategy, TimeStrategy
from recognition import Recognition
from recognition.high_walk import HighWalk
from recognition.open_high import OpenHigh
from recognition.quickly_pull_up import QuicklyPullUp
from recognition.turnover import Turnover


RecognitionInstance={
    RecognitionStrategy.OPEN_HIGH.value:OpenHigh,
    RecognitionStrategy.TURNOVER.value:Turnover,
    RecognitionStrategy.HIGH_WALK.value:HighWalk,
    RecognitionStrategy.QUICKLY_PULL_UP.value:QuicklyPullUp,
}

class RecognitionContext:
    def __init__(self):
        self.recognition_map: Dict[str, Dict[str, Recognition]] = {}

    def register(self, recognition: Recognition) -> None:
        if recognition.time_strategy:
            for key in recognition.time_strategy:
                if key not in self.recognition_map:
                    self.recognition_map[key] = {}
                if recognition.type:
                    self.recognition_map[key][recognition.type] = recognition

    def get(self, time_strategy: TimeStrategy, type: Optional[RecognitionStrategy] = None) -> Optional[Any]:
        if type:
            return self.recognition_map.get(time_strategy, {}).get(type)
        else:
            return self.recognition_map.get(time_strategy)